//左下 本月人数与上月人数对比统计
(function () {
    //1.实例化对象
    var myChart = echarts.init(document.querySelector('#month_year_comparison'));
//2.指定配置项和数据

    $.ajax({
        url: "../statistics/contrast",
        type: "post",
        dataType: "json",
        success: function (datas) {
            var data = [datas.lrThisMonthCount, datas.lrLastMonthCount, datas.hgThisMonthCount, datas.hgLastMonthCount];

            var titlename = ["当月老人数量", "上月老人数量", "当月护工数量", "上月护工数量"];
            var myColor = ["#F8B448", "#1089E7","#F8B448", "#1089E7"];

            var option = {

                tooltip: {
                    trigger: 'axis',
                    axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                grid: {
                    // top: "20%",
                    // left: "22%",
                    // bottom: "10%"
                    top: "18%",
                    left: "25%",
                    bottom: "10%"
                },
                xAxis: {
                    show: false
                },
                yAxis: [
                    {
                        show: true,
                        data: titlename,
                        inverse: true,
                        axisLine: {
                            show: false
                        },
                        splitLine: {
                            show: false
                        },
                        axisTick: {
                            show: false
                        },
                        axisLabel: {
                            color: "#fff",
                            fontSize: fontSize(0.12),
                            rich: {
                                lg: {
                                    backgroundColor: "#339911",
                                    color: "#fff",
                                    borderRadius: 15,
                                    // padding: 5,
                                    align: "center",
                                    width: 15,
                                    height: 15
                                }
                            }
                        }
                    },

                ],

                series: [
                    {
                        name: "人数",
                        type: "bar",
                        yAxisIndex: 0,
                        data: data,
                        barCategoryGap: 50,
                        barWidth: 10,
                        itemStyle: {
                            normal: {
                                barBorderRadius: 20,
                                color: function(params) {
                                    var num = myColor.length;
                                    return myColor[params.dataIndex % num];
                                }
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                position: "inside",
                                formatter: "{c}"
                            }
                        }
                    },

                ]

            };
//3.把配置项给实例对象
            myChart.setOption(option);
            //4、让图表自适应屏幕
            window.addEventListener("resize",function () {
                    myChart.resize();
                }
            )
        }
    })

})();


function fontSize(res){
    let docEl = document.documentElement,
        clientWidth = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
    if (!clientWidth) return;
    let fontSize = 100 * (clientWidth / 1920);
    return res*fontSize;
}